<?php

require_once '../../includes/includes.php';

$error = $_FILES["image"]["error"];

    if ($error == UPLOAD_ERR_OK) {
        
        $picId = $_POST['picId'];
        
        $pics = getCleanPics();
        $pics = indexOf('id', $pics);
        
        $albums = getAlbums();
        $albums = indexOf('id', $albums);
        
        $picName = $pics[$picId]['source'];
        $albumName = $albums[$pics[$picId]['album_id']]['name'];
        
        $unlinkPath = '../../albums/' . $albumName . '/' . $picName;
        unlink($unlinkPath);
        
        move_uploaded_file( $_FILES["image"]["tmp_name"], "../../albums/" . $albumName . '/' . $picName);
        
    }

